<?php

//简单列表调用

/*
 * 函数说明：单条数据调用
 *
 * @access  public
 * @param   $tablename    string     表名称
 * @param   $where        string     条件
 * @param   $select       string     字段

 */
	function db_select_one($tablename,$where = 1 , $select = "*") {
		global $dosql;
		$SQL = "SELECT $select FROM  `#@__".$tablename."` WHERE $where";
		$row = $dosql->GetOne($SQL);
		return $row;
	}
	
/*
 * 函数说明：列表调用
 *
 * @access  public
 * @param   $tablename    string     表名称
 * @param   $where        string     条件
 * @param   $select       string     字段

 */
	function db_select_list($tablename, $where = 1 ,$select = "*") {
		global $dosql;
		$SQL = "SELECT $select FROM  `#@__".$tablename."` WHERE $where";
		$dosql->Execute($SQL);
		while($row = $dosql->GetArray()){$row_return[]=$row;}
		return $row_return;
	}
	
/*
 * 函数说明：查询双表
 *
 * @access  public
 * @param   $tablename    string     表名称
 * @param   $where        string     条件
 * @param   $select       string     字段

 */
	function db_select_all($tablename1,$tablename2,$where = 1 ,$select = "*") {
		global $dosql;
		$SQL = "SELECT $select FROM  `#@__".$tablename1."` as a, `#@__".$tablename2."` as b WHERE $where";
		$dosql->Execute($SQL);
		while($row = $dosql->GetArray()){$row_return[]=$row;}
		return $row_return;
	}


	/*
 * 函数说明：插入数据 INSERT
 * @access  public
 * @param   $tablename    string     表名称
 * @param   $arr        array     插入的字段 
 	$arr 格式 key=>valve,
	 	array(
			'title'=>$title,
			'name'=>$name,
			'address'=>$address,
	 	)
 */
	function db_select_insert($tablename,$arr) {
		global $dosql;
		foreach ($arr as $key => $value) {
			 $value= mysql_real_escape_string($value);
			 $keyArr[]="`".$key."`";
			 $valueArr[]="`".$value."`";
		}
 		$keys= implode(",", $keyArr);
 		$values=implode(",", $valueArr);
		$SQL = "INSERT INTO `#@__".$tablename."`(".$keys.") VALUES (".$values.")";
		$dosql->ExecNoneQuery($sql);
	}
